package bll

import (
	"jgt-oper/src/model"
	"jgt-oper/src/schema"
	"jgt-oper/src/util"
	"time"
)

// EEBll 门禁设备
type EEBll struct {
	EEModel model.IEntranceEquipment `inject:"IEntranceEquipment"`
}

// Create 创建数据
func (a *EEBll) Create(item *schema.EntranceEquipment) error {
	item.ID = 0
	item.RecordID = util.UUID()
	item.Created = time.Now().Unix()
	item.Deleted = 0
	return a.EEModel.Create(item)
}

// QueryPage 查询分页数据
func (a *EEBll) QueryPage(params schema.EntranceEquipment, pageIndex uint, pageSize uint) (int64, []*schema.EntranceEquipment, error) {
	return a.EEModel.QueryPage(params, pageIndex, pageSize)
}

// GetDetailCard 查询详情
func (a *EEBll) GetDetailCard(param string) (*schema.EntranceEquipment, error) {
	result, err := a.EEModel.GetDetailCard(param)
	if err != nil {
		return nil, err
	}
	//循环查询出该门禁设备的直接父节点
	//	 检查页面是否缺少字段
	//初始化slice
	//if len(result.ParentEquipmentNodes) > 0 {
	//	result.ParentNodes = make([]*schema.EntranceEquipment, 0)
	//	for _, node := range result.ParentEquipmentNodes {
	//		nodeDetail, e := a.EEModel.GetDetailCard(node)
	//		if e != nil {
	//			return nil, e
	//		}
	//		result.ParentNodes = append(result.ParentNodes, nodeDetail)
	//	}
	//}
	return result, nil
}

// QueryTreeNode  查询节点树
func (a *EEBll) QueryTreeNode() ([]*schema.BuildingNode, error) {
	return a.EEModel.QueryTreeNode()
}

// Delete 标记删除
func (a *EEBll) Delete(param string) error {
	return a.EEModel.Delete(param)
}

// GetEquipmentInfo 查询门禁信息
func (a *EEBll) GetEquipmentInfo(param string) ([]*schema.GetEquipmentInfo, error) {
	return a.EEModel.GetEquipmentInfo(param)
}

// QueryEntranceArray 批量查询门禁设备信息
func (a *EEBll) QueryEntranceArray(entranceIDArray []string) ([]*schema.EntranceEquipment, error) {
	return a.EEModel.QueryEntranceArray(entranceIDArray)
}
